<template>
  <div class="file-uploader">
    <div class="credential-infor">
      <van-uploader
        :after-read="afterRead"
        class="img-uploader"
        :max-count="1"
        v-model="fileList"
      />
    </div>
  </div>
</template>

<script>
export default {
  name: "FileUploader",

  data() {
    return {
      fileList: [],
    };
  },

  created() {},

  computed: {},

  methods: {
    afterRead(file) {
      // 此时可以自行将文件上传至服务器
      console.log(file);

      let imgFile = new FormData();

      imgFile.append("fileType", "IMAGE");

      imgFile.append("file", this.fileList[0].file);
      console.log(imgFile);

      //   this.$service.apply
      //     .uploadImage({
      //       data: imgFile,
      //     })
      //     .then((r) => {
      //       if (r.data.success) {
      //         this.imgKey.push(r.data.data.key);
      //       }
      //     });
    },
  },
};
</script>

<style lang="less">
.file-uploader {
  .credential-infor {
    margin: 20px;

    height: 100px;
  }
}
</style>
